#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
通过读取网络设备CMDB表，将相同分类的设备IP放到一个列表内，然后循环列表进行并发采集设备配置信息；
这里先进行CMDB表输出成各个IP列表
然后对不同厂商和地区的设备采集进行不同采集函数编写
最后再对不同采集函数进行并发处理
"""

import os
import xlrd3
import pexpect
from pexpect import pxssh
import time
import socket
import threading   #多线程，SSH属于IO密集型程序

local_time = time.strftime("%Y%m%d%H%M", time.localtime())
lock = threading.Lock()

#获取地址列表
"""
这里ConfigDeviceList.xlsx表头如下字段：
管理地址	设备名称	设备类别	                             设备级别	                          厂商	                                 归属地
IP地址      命名       枚举值[交换机|路由器|防火墙|负载均衡]      枚举值[汇聚设备|接入设备]             枚举值[UNIS|H3C|HUAWEI|山石|CP|DP|PA]  自定义数据中心所在地
"""
def ip_list():
    global ip_h3c_cs_list,ip_hw_cs_list,ip_hillstone_cs_list,ip_pa_cs_list,ip_cp_cs_list,ip_dp_cs_list,ip_hw_jq_cs_list,ip_hillstone_jq_cs_list,ip_hw_sj_cs_list,ip_hillstone_sj_cs_list,ip_dp_sj_cs_list,ip_dp_lj_fz_cs_list
    ip_h3c_cs_list = []
    ip_hw_cs_list = []
    ip_hillstone_cs_list = []
    ip_pa_cs_list = []
    ip_cp_cs_list = []
    ip_dp_cs_list = []
    ip_hw_jq_cs_list = []
    ip_hillstone_jq_cs_list = []
    ip_hw_sj_cs_list = []
    ip_hillstone_sj_cs_list = []
    ip_dp_sj_cs_list = []
    ip_dp_lj_fz_cs_list = []
    device_excel_path = '/app/backup/device_info/ConfigDeviceList.xlsx'
    device_data = xlrd3.open_workbook(device_excel_path, encoding_override='utf-8')
    device_data_sheet = device_data.sheet_by_name('backup_cmdb')
    device_data_sheet_nrows = device_data_sheet.nrows  # 行
    for i in range(1, device_data_sheet_nrows):
        device_data_info = device_data_sheet.row_values(i)
        if device_data_info[4] == "H3C" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海":
            ip_h3c_cs = device_data_info[0]
            ip_h3c_cs_list.append(ip_h3c_cs)
        elif device_data_info[4] == "HUAWEI" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海":
            ip_hw_cs = device_data_info[0]
            ip_hw_cs_list.append(ip_hw_cs)
        elif device_data_info[4] == "山石" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海":
            ip_hillstone_cs = device_data_info[0]
            ip_hillstone_cs_list.append(ip_hillstone_cs)
        elif device_data_info[4] == "PA" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海":
            ip_pa_cs = device_data_info[0]
            ip_pa_cs_list.append(ip_pa_cs)
        elif device_data_info[4] == "CP" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海":
            ip_cp_cs = device_data_info[0]
            ip_cp_cs_list.append(ip_cp_cs)
        elif device_data_info[4] == "DP" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海":
            ip_dp_cs = device_data_info[0]
            ip_dp_cs_list.append(ip_dp_cs)
        elif device_data_info[4] == "HUAWEI" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海金桥":
            ip_hw_jq_cs = device_data_info[0]
            ip_hw_jq_cs_list.append(ip_hw_jq_cs)
        elif device_data_info[4] == "山石" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "上海金桥":
            ip_hillstone_jq_cs = device_data_info[0]
            ip_hillstone_jq_cs_list.append(ip_hillstone_jq_cs)
        elif device_data_info[4] == "HUAWEI" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "成都":
            ip_hw_sj_cs = device_data_info[0]
            ip_hw_sj_cs_list.append(ip_hw_sj_cs)
        elif device_data_info[4] == "山石" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "成都":
            ip_hillstone_sj_cs = device_data_info[0]
            ip_hillstone_sj_cs_list.append(ip_hillstone_sj_cs)
        elif device_data_info[4] == "DP" and device_data_info[2] == "防火墙" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "成都":
            ip_dp_sj_cs = device_data_info[0]
            ip_dp_sj_cs_list.append(ip_dp_sj_cs)
        elif device_data_info[4] == "DP" and device_data_info[2] == "负载均衡" and device_data_info[3] == "汇聚设备" and device_data_info[5] == "成都":
            ip_dp_lj_fz_cs = device_data_info[0]
            ip_dp_lj_fz_cs_list.append(ip_dp_lj_fz_cs)

#定义采集函数
def get_h3c_cs_config(ip, username, password, file_name_h3c_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_h3c_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length disable')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length disable')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备配置信息出错')
        print(e)

def get_hw_cs_config(ip, username, password, file_name_hw_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_hw_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length 0 temporary')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length 0 temporary')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_hw_jq_cs_config(ip, username, password, file_name_hw_jq_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_hw_jq_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length 0 temporary')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length 0 temporary')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_hillstone_cs_config(ip, username, password, file_name_hillstone_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['#']
        with open(file_name_hillstone_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal length 0')
                child.expect(prompt)
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal length 0')
                child.expect(prompt)
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_hillstone_jq_cs_config(ip, username, password, file_name_hillstone_jq_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['#']
        with open(file_name_hillstone_jq_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal length 0')
                child.expect(prompt)
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal length 0')
                child.expect(prompt)
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_pa_cs_config(ip, username, password, file_name_pa_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        prompt1 = ['#']
        with open(file_name_pa_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('set cli config-output-format set')
                child.expect(prompt)
                child.sendline('set cli pager off')
                child.expect(prompt)
                child.sendline('configure')
                child.expect(prompt1)
                child.sendline('show')
                child.expect(prompt1)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('set cli config-output-format set')
                child.expect(prompt)
                child.sendline('set cli pager off')
                child.expect(prompt)
                child.sendline('configure')
                child.expect(prompt1)
                child.sendline('show')
                child.expect(prompt1)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备配置信息出错')

def get_cp_cs_config(ip, username, password, file_name_cp_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_cp_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_dp_cs_config(ip, username, password, file_name_dp_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_dp_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal line 0')
                child.expect(prompt)
                child.sendline('show running-config')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal line 0')
                child.expect(prompt)
                child.sendline('show running-config')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_dp_sj_cs_config(ip, username, password, file_name_dp_sj_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_dp_sj_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal line 0')
                child.expect(prompt)
                child.sendline('show running-config')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal line 0')
                child.expect(prompt)
                child.sendline('show running-config')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_hw_sj_cs_config(ip, username, password, file_name_hw_sj_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_hw_sj_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length 0 temporary')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('screen-length 0 temporary')
                child.expect(prompt)
                child.sendline('display current-configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_hillstone_sj_cs_config(ip, username, password, file_name_hillstone_sj_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['#']
        with open(file_name_hillstone_sj_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal length 0')
                child.expect(prompt)
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal length 0')
                child.expect(prompt)
                child.sendline('show configuration')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

def get_dp_lj_fz_cs_config(ip, username, password, file_name_dp_lj_fz_cs):
    try:
        os.system('> ~/.ssh/known_hosts')
        conn_str = 'ssh '+ username + '@' + ip
        prompt = ['>']
        with open(file_name_dp_lj_fz_cs,"ab+") as f:
            child = pexpect.spawn(conn_str,maxread=100000,timeout=None)
            i = child.expect(['yes/no','[P|p]assword:'])
            if i == 0:
                child.sendline('yes')
                child.expect('[P|p]assword:')
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal line 0')
                child.expect(prompt)
                child.sendline('show running-config')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
                f.close
            elif i == 1:
                child.sendline(password)
                child.expect(prompt)
                child.logfile = f
                child.sendline('terminal line 0')
                child.expect(prompt)
                child.sendline('show running-config')
                child.expect(prompt)
                child.expect(pexpect.EOF, timeout = None)
                child.close()
            else:
                print(ip + '连接主机超时，请检查密码和网络')
            f.close
    except Exception as e:
        print(ip + '获取设备device信息出错')

#定义采集线程
#采集华三防火墙配置 - 上海
def th_h3c_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_h3c_cs_list:
        file_name_h3c_cs = '/app/backup/all_config_fw/' + ip + '_SH_FW_H3C_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_h3c_cs_config,args=(ip,username,password,file_name_h3c_cs))
        time.sleep(1)
        t.start()

#采集华为防火墙配置 - 上海
def th_hw_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_hw_cs_list:
        file_name_hw_cs = '/app/backup/all_config_fw/' + ip + '_SH_FW_HUAWEI_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_hw_cs_config,args=(ip,username,password,file_name_hw_cs))
        time.sleep(1)
        t.start()

#采集华为防火墙配置 - 上海金桥
def th_hw_jq_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_hw_jq_cs_list:
        file_name_hw_jq_cs = '/app/backup/all_config_fw/' + ip + '_JQ_FW_HUAWEI_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_hw_jq_cs_config,args=(ip,username,password,file_name_hw_jq_cs))
        time.sleep(1)
        t.start()

#采集华为防火墙配置 - 成都
def th_hw_cd_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_hw_sj_cs_list:
        file_name_hw_sj_cs = '/app/backup/all_config_fw/' + ip + '_CD_FW_HUAWEI_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_hw_sj_cs_config,args=(ip,username,password,file_name_hw_sj_cs))
        time.sleep(1)
        t.start()

#采集山石防火墙配置 - 上海
def th_hillstone_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_hillstone_cs_list:
        file_name_hillstone_cs = '/app/backup/all_config_fw/' + ip + '_SH_FW_山石_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_hillstone_cs_config,args=(ip,username,password,file_name_hillstone_cs))
        time.sleep(1)
        t.start()

#采集山石防火墙配置 - 上海金桥
def th_hillstone_jq_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_hillstone_jq_cs_list:
        file_name_hillstone_jq_cs = '/app/backup/all_config_fw/' + ip + '_JQ_FW_山石_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_hillstone_jq_cs_config,args=(ip,username,password,file_name_hillstone_jq_cs))
        time.sleep(1)
        t.start()

#采集山石防火墙配置 - 成都
def th_hillstone_cd_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_hillstone_sj_cs_list:
        file_name_hillstone_sj_cs = '/app/backup/all_config_fw/' + ip + '_CD_FW_山石_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_hillstone_sj_cs_config,args=(ip,username,password,file_name_hillstone_sj_cs))
        time.sleep(1)
        t.start()

#采集PA防火墙配置 - 上海
def th_pa_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_pa_cs_list:
        file_name_pa_cs = '/app/backup/all_config_fw/' + ip + '_SH_FW_PA_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_pa_cs_config,args=(ip,username,password,file_name_pa_cs))
        time.sleep(1)
        t.start()

#采集CP防火墙配置 - 上海
def th_cp_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_cp_cs_list:
        file_name_cp_cs = '/app/backup/all_config_fw/' + ip + '_SH_FW_CP_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_cp_cs_config,args=(ip,username,password,file_name_cp_cs))
        time.sleep(1)
        t.start()

#采集DP防火墙配置 - 上海
def th_dp_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_dp_cs_list:
        file_name_dp_cs = '/app/backup/all_config_fw/' + ip + '_SH_FW_DP_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_dp_cs_config,args=(ip,username,password,file_name_dp_cs))
        time.sleep(1)
        t.start()

#采集DP防火墙配置 - 成都
def th_dp_cd_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_dp_sj_cs_list:
        file_name_dp_sj_cs = '/app/backup/all_config_fw/' + ip + '_CD_FW_DP_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_dp_sj_cs_config,args=(ip,username,password,file_name_dp_sj_cs))
        time.sleep(1)
        t.start()

#采集DP负载均衡配置 - 上海
def th_dp_sh_fz_cs_config():
    ip_list()
    time.sleep(2)
    username = '*****'
    password = '*****'
    for ip in ip_dp_lj_fz_cs_list:
        file_name_dp_lj_fz_cs = '/app/backup/all_config_fz/' + ip + '_SH_FZ_DP_CS_Config_' + local_time + '.txt'
        t = threading.Thread(target=get_dp_lj_fz_cs_config,args=(ip,username,password,file_name_dp_lj_fz_cs))
        time.sleep(1)
        t.start()

if __name__ == "__main__":
    th_h3c_cs_config()
    th_hw_cs_config()
    th_hillstone_cs_config()
    th_pa_cs_config()
    th_dp_cs_config()
    th_hw_jq_cs_config()
    th_hillstone_jq_cs_config()
    th_hw_cd_cs_config()
    th_hillstone_cd_cs_config()
    th_dp_cd_cs_config()
    th_dp_sh_fz_cs_config()

    local_time_p = time.strftime("%Y%m%d%H", time.localtime())
    print("get_config" + "_" + local_time_p + "_执行成功")